package com.jie.config;
 
import org.springframework.boot.web.client.RestTemplateBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
import org.springframework.web.client.RestTemplate;
 
/**
 * 把RestTemplate注入Spring IOC容器
 * @author cr949
 */
@Configuration
public class RestTemplateConfiguration {
 
    @Bean
    public RestTemplate restTemplate(RestTemplateBuilder restTemplateBuilder) {
 
        RestTemplate restTemplate = restTemplateBuilder.build();
        // 设置HTTP request (请求)和response (响应)的转换器
        restTemplate.getMessageConverters().add(new MappingJackson2HttpMessageConverter());
        return restTemplate;
    }
}